import { lazy } from "react";
import { createBrowserRouter, Navigate, type RouteObject } from "react-router";

const BaseLayout = lazy(() => import("@/layout/BaseLayout"));
const DashboardLayout = lazy(() => import("@/layout/DashboardLayout"));
// home
const Application = lazy(() => import("@/views/Home/Application"));
const Config = lazy(() => import("@/views/Home/Config"));
const DatasetView = lazy(() => import("@/views/Home/Dataset"));
const DatasetOverview = lazy(() => import("@/views/Home/Dataset/Overview"));
const DatasetDetail = lazy(() => import("@/views/Home/Dataset/Detail"));
const Search = lazy(() => import("@/views/Home/Search"));
// login
const Login = lazy(() => import("@/views/Login"));
const NotFound = lazy(() => import("@/components/NotFound"));

export const routes: RouteObject[] = [
  {
    path: "/",
    element: <BaseLayout />,
    children: [
      {
        path: "",
        index: true,
        element: <Navigate to="dashboard" replace />,
      },
      {
        path: "dashboard",
        element: <DashboardLayout />,
        handle: { title: "首页" },
        children: [
          {
            index: true,
            element: <Navigate to="application" replace />,
          },
          {
            path: "application",
            element: <Application />,
            handle: { title: "应用" },
          },
          {
            path: "config",
            element: <Config />,
            handle: { title: "配置" },
          },
          {
            path: "dataset",
            element: <DatasetView />,
            handle: { title: "数据集" },
            children: [
              {
                path: "",
                index: true,
                element: <DatasetOverview />,
              },
              {
                path: ":id",
                element: <DatasetDetail />,
              },
            ],
          },
          {
            path: "search",
            element: <Search />,
            handle: { title: "检索" },
          },
        ],
      },
    ],
  },
  {
    path: "login",
    element: <Login />,
  },
  {
    path: "*",
    element: <NotFound />,
  },
];

export default createBrowserRouter(routes, { basename: "/" });
